package de.wojenko.sps;

import java.util.List;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;

import com.google.common.collect.Lists;

@XmlRootElement(name = "backlog-item")
public class XmlUserStory implements BacklogItem {

	private String id = "";
	private int sprintNumber;
	private String name = "";
	private String content = "";
	private List<XmlBacklogItemArtefact> acceptanceCriteriaList;
	private List<XmlBacklogItemArtefact> taskList;

	@Override
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@Override
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Override
	public String getContent() {
		return this.content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public int getSprintNumber() {
		return sprintNumber;
	}

	public void setSprintNumber(int sprintNumber) {
		this.sprintNumber = sprintNumber;
	}

	@SuppressWarnings("unchecked")
	@Override
	@XmlElementWrapper(name = "uat-list")
	@XmlElement(name = "artefact")
	public List<XmlBacklogItemArtefact> getAcceptanceCriteriaList() {
		if (acceptanceCriteriaList == null) {
			acceptanceCriteriaList = Lists.newArrayList();
		}
		return acceptanceCriteriaList;
	}

	public void setAcceptanceCriteriaList(
			List<XmlBacklogItemArtefact> acceptanceCriteriaList) {
		this.acceptanceCriteriaList = acceptanceCriteriaList;
	}

	@SuppressWarnings("unchecked")
	@Override
	@XmlElementWrapper(name = "task-list")
	@XmlElement(name = "artefact")
	public List<XmlBacklogItemArtefact> getTaskList() {
		if (taskList == null) {
			taskList = Lists.newArrayList();
		}
		return taskList;
	}

	public void setTaskList(List<XmlBacklogItemArtefact> taskList) {
		this.taskList = taskList;
	}

	@Override
	public BacklogItemArtefact addAcceptanceCriteria() {
		XmlBacklogItemArtefact artefact = new XmlBacklogItemArtefact();
		getAcceptanceCriteriaList().add(artefact);
		return artefact;
	}

	@Override
	public XmlBacklogItemArtefact addTask() {
		XmlBacklogItemArtefact artefact = new XmlBacklogItemArtefact();
		getTaskList().add(artefact);
		return artefact;
	}
}
